package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CrmMemberAddDTO;
import org.jsola.hr.dto.CrmMemberUpdateDTO;
import org.jsola.hr.entity.CrmMemberDO;
import org.jsola.hr.query.CrmMemberQuery;
import org.jsola.hr.service.ICrmMemberService;
import org.jsola.hr.vo.CrmMemberVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 成员表
 *
 * @author zhr
 */
@Component
public class CrmMemberTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICrmMemberService crmMemberService;

    /**
     * 生成add测试数据
     * @return CrmMemberAddDTO
     */
    public CrmMemberAddDTO getCrmMemberAddDTO(){
        CrmMemberAddDTO crmMemberAddDTO = new CrmMemberAddDTO();
        crmMemberAddDTO.setName(getRandomValue("varchar",100));
        crmMemberAddDTO.setJurisdiction(SafeKit.getInteger(getRandomValue("int",1)));
        crmMemberAddDTO.setUserId(getRandomValue("varchar",32));
        return crmMemberAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CrmMemberUpdateDTO
     */
    public CrmMemberUpdateDTO getCrmMemberUpdateDTO(CrmMemberVO crmMemberVO){
        return crmMemberService.selectDOById(crmMemberVO.getId(), SITE_ID).to(CrmMemberUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CrmMemberQuery
     */
    public CrmMemberQuery getCrmMemberQuery() {
        CrmMemberQuery crmMemberQuery = new CrmMemberQuery();
        List<CrmMemberDO> crmMemberDOList = crmMemberService.list(new CrmMemberDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(crmMemberDOList)) {
            CrmMemberDO crmMemberDO = crmMemberDOList.get(0);
            crmMemberQuery = crmMemberDO.to(CrmMemberQuery.class);
        }
        return crmMemberQuery;
    }

    /**
     * 保存示例
     * @return CrmMemberVO
     */
    public CrmMemberVO saveCrmMemberExample(){
        CrmMemberAddDTO addDTO = this.getCrmMemberAddDTO();
        CrmMemberVO crmMemberVO = crmMemberService.save(addDTO,buildTokenUser());
        return crmMemberVO;
    }


}

